/*
 * Copyright (C) 2009 Rob Cash
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SubscriptionTypeWizardPanel.java
 */

package org.robcash.apps.messagepopup.view.wizard;

import org.robcash.apps.messagepopup.view.components.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.robcash.commons.swing.wizard.impl.BaseWizardPanel;

/**
 *
 * @author Rob
 */
public class SubscriptionTypeWizardPanel
        extends BaseWizardPanel<SubscriptionTypeChooser>
        implements ChangeListener {

    private SubscriptionTypeChooser typeChooser;

    public SubscriptionTypeWizardPanel(String objectId) {
        super(objectId);
        typeChooser = new SubscriptionTypeChooser();
        typeChooser.addChangeListener(this);
        setComponent(typeChooser);
    }

    /**
     * Override this class to provide the Object-based identifier of the panel that the
     * user should traverse to when the Next button is pressed. Note that this method
     * is only called when the button is actually pressed, so that the panel can change
     * the next panel's identifier dynamically at runtime if necessary. Return null if
     * the button should be disabled. Return FinishIdentfier if the button text
     * should change to 'Finish' and the dialog should end.
     * @return Object-based identifier.
     */
    @Override
    public String getNextPanelId() {
        if ( SubscriptionTypeChooser.LOCAL_FILE.equals(typeChooser.getSelectedSubscriptionType()) ) {
            return SubscriptionModel.LOCAL_FILE;
        }
        else if ( SubscriptionTypeChooser.REMOTE_FILE.equals(typeChooser.getSelectedSubscriptionType()) ) {
            return SubscriptionModel.REMOTE_FILE;
        }
        else {
            return null;
        }
    }

    /**
     * Receive notification that something has changed
     * @param evt Change event
     */
    public void stateChanged(ChangeEvent evt) {
        if ( evt.getSource().equals(typeChooser) ) {
            // Notify wizard that panel state has changed
            fireChangeListenerStateChanged(new ChangeEvent(this));
        }
    }
}
